/**
 *
 * Module        : Module Size
 * Authors       : Ben Kwint & Arie van der Veek
 * Date          : November 13th 2011
 * Description   : Uses the Lines of code measurement to determin
 *                 the size of a module in terms of lines of code.
 *
 */
module Metrics::ModuleSize

import IO;
import Set;
import Relation;
import List;

import lang::java::jdt::Java;
import lang::java::jdt::JDT;

import Metrics::Regular::CommentLines;
import Metrics::Regular::EmptyLines;
import Metrics::Regular::StringUtils;
import Metrics::Loc;
import InOut::Input;



/* 	A module defined by SIG is for Java a Class.
	This module provides methods to calculate different
	metrics for modultes on java projects.
	
	Question, is it truelly so that a Class is a module?
	Packages should also be a module?
	Question: Should test packages be included? They are part of your system.
*/

// 	countClasses parses a project and then counts classes.
    public int countClasses(BindingRel classes){

	int classesCounter = 0;
	visit(classes) {
	 case class(_): classesCounter = classesCounter + 1;
   	};
   	return classesCounter;

}

// 	countLOCPerClass parses a project and then counts the lines of code per class.
public list[tuple[str,int]] countLOCPerClass(BindingRel classes){
	return
		for( loc fileLocation <- domain(classes))
		{
	 		int nrOfLines = countLOCForClass(classLocation);
			str className = getQualifiedMethodsName((head(toList(classes[fileLocation]))));
			append <className,nrOfLines>;
		}
}

public int countLOCForClass(loc classLocation){
	list[str] lines = readCodeBlockFromFile(classLocation);
	int nrOfLines = countLinesOfCode(lines);
	return nrOfLines;
}